package com.ymall.common;

import com.ymall.util.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Created by EvenLee on 2018/1/14.
 */
@Component
@Slf4j
public class RedissonManager {
    private Config config = new Config ();

    private Redisson redisson = null;

    public Redisson getRedisson(){
        return redisson;
    }

    private static String redis1Ip = PropertiesUtil.getProperty("");
    private static Integer redis1Port = Integer.parseInt(PropertiesUtil.getProperty(""));
    private static String redis2Ip = PropertiesUtil.getProperty("");
    private static Integer redis2Port = Integer.parseInt(PropertiesUtil.getProperty(""));

    @PostConstruct
    private void init(){

        config.useMasterSlaveServers ().setMasterAddress ("127.0.0.1:6379").addSlaveAddress ("127.0.0.1:6380");
//        config.useClusterServers().addNodeAddress().addNodeAddress()
        try {
            redisson = (Redisson) Redisson.create (config);
        }catch (Exception e){
            log.error ("redisson init error",e);
        }
        log.info ("redisson init Success");

    }
}
